package com.zsd.android.ffmpegdemo;

import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class VideoPlayer implements SurfaceHolder.Callback {

    static {
        System.loadLibrary("native-lib");
    }

    private SurfaceHolder mSurfaceHolder;

    public void setSurfaceView(SurfaceView surfaceView) {
        if (null != mSurfaceHolder) {
            this.mSurfaceHolder.removeCallback(this);
        }
        mSurfaceHolder = surfaceView.getHolder();
        mSurfaceHolder.addCallback(this);
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {

    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        this.mSurfaceHolder = holder;
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

    }

    public void start(String path) {
        new Thread(() -> {
            nativeStart(path, mSurfaceHolder.getSurface());
        }).start();
    }

    public native void nativeStart(String path, Surface surface);

    public native void nativeSound(String input, String output);
}
